﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FgoDataCrawler.Entity;
using FgoDataCrawler.Utility;
using Newtonsoft.Json;

namespace FgoDataCrawler.Message.FgoWiki
{
    public class Servant
    {
        public int ID { get; set; }
        public string NAME { get; set; }
        public string NAME_JP { get; set; }
        public string NAME_EN { get; set; }
        public string CLASS { get; set; }
        public int? COST { get; set; }
        public int CARD_BUSTER { get; set; }
        public int CARD_ARTS { get; set; }
        public int CARD_QUICK { get; set; }
        public string Property { get; set; }  // 特性
        public string Camp { get; set; }
        public string Gender { get; set; }  // 性别
        public int STAR { get; set; }

        // No.081的例外情况，以下三个值会有两个结果
        public string Crit { get; set; }  // 暴击星获取率 
        public string Death { get; set; }  // 固有即死率
        public string CritPr { get; set; } // 暴击星分配权重 

        public string InitiativeNp { get; set; }  // 宝具NP获取率
        public string Passive { get; set; }  // 受伤NP获取率
        public int? ArtHit { get; set; }  // 攻击次数
        public int? BusHit { get; set; }
        public int? QuiHit { get; set; }
        public int? EXHit { get; set; }
        public string Attributes { get; set; }  // 属性（主要是九宫格，也有特殊的）
        public string TdPointQ { get; set; }
        public string TdPointA { get; set; }
        public string TdPointB { get; set; }
        public string TdPointEx { get; set; }

        public int Cost
        {
            get
            {
                if (COST == null) return 0;
                return COST.Value;
            }
        }

        public int ArtsHits
        {
            get
            {
                if (ArtHit == null) return 0;
                return ArtHit.Value;
            }
        }
        public int QuickHits
        {
            get
            {
                if (QuiHit == null) return 0;
                return QuiHit.Value;
            }
        }
        public int BusterHits
        {
            get
            {
                if (BusHit == null) return 0;
                return BusHit.Value;
            }
        }
        public int ExHits
        {
            get
            {
                if (EXHit == null) return 0;
                return EXHit.Value;
            }
        }

        public ServantInfo ToServiceInfo()
        {
            ServantInfo si = new ServantInfo();
            si.Id = ID;
            si.JapaneseName = NAME_JP;
            si.EnglishName = NAME_EN;
            si.ChineseName = NAME;
            si.Class = CLASS;
            si.Rarity = STAR;
            si.Cost = Cost;
            si.BusterCardAmount = CARD_BUSTER;
            si.ArtsCardAmount = CARD_ARTS;
            si.QuickCardAmount = CARD_QUICK;
            si.Attribute = Camp;  // 天地人星兽
            si.StarGeneration = NumberConvert.PercentToDouble(Crit);
            si.DeathRate = NumberConvert.PercentToDouble(Death);
            si.StarAbsorption = NumberConvert.PercentToInt(CritPr);
            si.NpChargeAtk = NumberConvert.PercentToDouble(InitiativeNp);
            si.NpChargeDef = NumberConvert.PercentToDouble(Passive);
            si.BusterHits = BusterHits;
            si.ArtsHits = ArtsHits;
            si.QuickHits = QuickHits;
            si.ExHits = ExHits;
            si.Alignments = Attributes;  // 九宫格
            si.Gender = NumberConvert.ToGenderId(Gender);

            return si;
        }
    }
}
